package top.jiangqiang.qianyi.common.properties;

import jakarta.annotation.PostConstruct;
import lombok.Data;
import org.dromara.hutool.core.io.file.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import top.jiangqiang.qianyi.common.constants.GlobalConstants;

import java.util.Map;

@Configuration
@ConfigurationProperties(prefix = GlobalConstants.GLOBAL_PREFIX + ".file")
@Data
public class FileProperties {
    /**
     * 静态资源路径映射
     */
    private Map<String, String> staticResourceMapping;
    /**
     * 文件上传路径，如果没有指定上传路径，默认使用此路径
     */
    @Value("#{systemProperties['os.name'].toString().toLowerCase().startsWith('windows') ?'D:/qy/uploadPath':'./uploadPath'}")
    private String uploadPath;

    @PostConstruct
    public void initDir() {
        if (!FileUtil.exists(uploadPath)) {
            FileUtil.mkdir(uploadPath);
        }
    }
}
